package com.ztjy.sys.biz.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ztjy.bean.Dept;
import com.ztjy.bean.Users;
import com.ztjy.sys.biz.UsersBiz;
import com.ztjy.sys.dao.DeptDao;
import com.ztjy.sys.dao.UsersDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 用户的业务逻辑
 */
@Service
public class UsersBizImpl implements UsersBiz {
    @Autowired
    private UsersDao udao;
    @Autowired
    private DeptDao ddao;

    @Override
    public Users login(String uname, String upwd) {
        Users users = udao.login(uname, upwd);
        return users;
    }

    @Override
    public PageInfo<Users> findAllPage(Users users, Integer pageNo, Integer pageSize) {
        PageHelper.startPage(pageNo, pageSize);
        List<Users> all = udao.findAll(users);
        PageInfo<Users> pageInfo = new PageInfo<Users>(all);
        return pageInfo;
    }

    @Override
    public List<Users> findAllUsers(Users users) {
        return udao.findAll(users);
    }

    @Override
    public boolean addUsers(Users users) {
        boolean flag = false;
        try {
            flag = udao.addUsers(users);
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public boolean updateUsers(Users users) {
        boolean flag = false;
        try {
            flag = udao.updateUsers(users);
        } catch (Exception e) {
            flag = false;
            e.printStackTrace();
        }
        return flag;
    }

    @Override
    public Users detailsUsers(Integer id) {
        return udao.findUsersById(id);
    }

    @Override
    public List<Dept> findAllDept() {
        Dept dept = new Dept();
        dept.setDeptState("1");//查询正常的
        return ddao.selectAllDept(dept);
    }

    @Override
    public List<Users> findAllRepJobUsers() {
        return udao.findAllRepJobUsers();
    }

}
